package com.ff.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ff.model.Fuser;

@Controller
@RequestMapping("/fuser")
public class FuserContorller extends AllController {
	@RequestMapping("jump00")//跳转到登录页面
	public String jump00() {
		return "login";
	}
	@RequestMapping("fuserlogin")//登录功能
	public String login(ModelMap mm,String fusername,String fpassword) {
		Fuser fu=fservice.login(fusername, fpassword);
		String cd="fuser";
		if(fu!=null) {
			if(fu.getPower()!=0)
				return "redirect:/wares/jump00?sid="+fu.getFid();
			else
				return "redirect:/fuser/cdjump00?cd="+cd;
		}
		else {
			String user="账号或密码输入错误！";
			mm.put("up", user);
		return "login";
		}
		
	}
	
	@RequestMapping("jump01")//跳转到注册页面
	public String jump01() {
		return "register";
	}
	
	@RequestMapping("register")//注册功能
	public String register(ModelMap mm,Fuser fuser) {
		fuser.setPower(1);
		fservice.register1(fuser);
		return "redirect:/fuser/jump00";
			
	}
	
	
	@RequestMapping("/cdjump00")//跳转到后台
	public String cdjump00(ModelMap mm,String cd) {
		mm.put("cd", cd);
		return "f_home";
	}
	
	@RequestMapping("/cdselectall")//分页查询用户数据
	public String cdselectall(ModelMap mm,int id) {
		int count=fservice.find_();
		mm.put("count", count);
		if(id<1)
			id=1;
		if(id>count)
			id=count;
		System.out.println(1);
		List<Fuser> listfuser=fservice.find_limit(id);
		mm.put("fuser", listfuser);
		mm.put("ts",id);
		return "f_fuser";
	}
	
	@RequestMapping("/cddelete")//后台删除数据
	public String cddelete(int id) {
		String cd="fuser";
		fservice.delete1(id);
		return "redirect:/fuser/cdjump00?cd="+cd;
	}
	
	@RequestMapping("/cdjumpinsert")//跳转到后台添加页面
	public String cdjumpinsert() {
		return "f_fuser_insert";
	}
	
	@RequestMapping("/cdinsert")//后台添加数据
	public String cdinsert(Fuser f) {
		String cd="fuser";
		f.setPower(1);
		fservice.register1(f);
		return "redirect:/fuser/cdjump00?cd="+cd;
				
	}
	
	@RequestMapping("/cdjumpupdate")//跳转到后台修改页面
	public String cdjumpupdate(ModelMap mm,int id) {
		Fuser f=fservice.find11(id);
		mm.put("fuser", f);
		return "f_fuser_update";
	}
	
	@RequestMapping("/cdupdate")//后台修改数据
	public String cdupdate(ModelMap mm,Fuser f) {
		String cd="fuser";
		System.out.println(f.getFid());
		fservice.update1(f);
		return "redirect:/fuser/cdjump00?cd="+cd;
	}
	
	@RequestMapping("jump02")//跳转到个人中心
	public String jump02(ModelMap mm,int sid) {
		Fuser f=fservice.find11(sid);
		mm.put("fuser", f);
		return "personal";
	}
	
	@RequestMapping("/jump02_id")//ID查询
	public String jump02_id(ModelMap mm,int sid) {
		Fuser f=fservice.find11(sid);
		mm.put("fuser", f);
		return "personal-information";
	}
	@RequestMapping("/jump02_update")//修改用户信息
	public String jump02_update(ModelMap mm,int sid) {
		Fuser f=fservice.find11(sid);
		mm.put("fuser", f);
		return "personal-update";
	}
	@RequestMapping("/update02")
	public String update02(ModelMap mm,Fuser f) {
		f.setPower(1);
		fservice.update1(f);
		return "redirect:/fuser/jump00";
	}
}
